<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Akademik extends Controller {

    public function __construct() {
        parent::__construct();

//        echo 'dashboard ctrl';

        Session::init();

        $loggeg = Session::get('loggedIn');
        $role = Session::get('role');

        if ($loggeg == false || $role != 'Admin') {
            Session::Destroy();
            header('location: ' . URL . 'error/index');
            exit;
        }
//        print_r($_SESSION['role']);
    }

    public function index() {

        $this->view->univList = $this->model->univList();
        $this->view->render('akademik/index');
    }

    public function index_jurusan() {

        $this->view->list_jurusan = $this->model->list_jurusan();
        $this->view->render('akademik/index_jurusan');
    }

    public function univForm() {
        $this->view->render('akademik/add_univ');
    }

    public function addSave() {

        $data['kd_univ'] = $_POST['kd_univ'];
        $data['nama'] = $_POST['nama'];

//        array_push($data, $array);
        $this->model->addUniv($data);

//        print_r($data);
        header('location:' . URL . 'akademik/index');
    }

    public function delete($id) {
        $this->model->deleteUniv($id);
        header('location:' . URL . 'akademik/index');
    }

    public function edit($id) {

//        $this->view->user = $this->model->editUser($id);
//        $this->view->render('user/edit_user');
    }

    public function add_jurusan() {

        $this->view->univList = $this->model->univList();

        $this->view->render('akademik/add_jurusan');
    }

    public function save_jurusan() {
        $data[] = $_POST['kd_univ'];
        $data[] = $_POST['kode_jurusan'];
        $data[] = $_POST['nama'];

//        var_dump($data);
        $this->model->save_jurusan($data);
        header('location:' . URL . 'akademik/index_jurusan');
    }

    public function edit_jurusan($id) {
        $this->view->univList = $this->model->univList();
        $this->view->edit_jurusan = $this->model->edit_jurusan($id);
        $this->view->render('akademik/edit_jurusan');
    }

    public function edit_save_jurusan($data) {
        $data['id'] = $_POST['id'];
        $data['kd_univ'] = $_POST['kd_univ'];
        $data['kode_jurusan'] = $_POST['kode_jurusan'];
        $data['nama'] = $_POST['nama'];

        $this->model->edit_save_jurusan($data);
        header('location:' . URL . 'akademik/index_jurusan');
    }

    public function delete_jurusan($id) {
        $this->model->delete_jurusan($id);
        header('location:' . URL . 'akademik/index_jurusan');
    }

    public function index_makul() {
        $this->view->list_makul = $this->model->list_makul();
        $this->view->render('akademik/index_makul');
    }

    public function add_makul() {
        $this->view->univList = $this->model->univList();
        $this->view->list_jurusan = $this->model->list_jurusan();
        $this->view->render('akademik/add_makul');
    }

    public function save_makul() {
        $data['kd_univ'] = $_POST['kd_univ'];
        $data['kd_jurusan'] = $_POST['kd_jurusan'];
        $data['kd_makul'] = $_POST['kode_makul'];
        $data['nama'] = $_POST['nama'];
        $this->model->save_makul($data);
    }

}

?>
